# 作者：lian
import copy
# a = [1,2,3]
# b = a
# b[0] = 10
# print(a)

def use_copy():
    c=[1,2,3]
    d=copy.copy(c)
    d[0]=10
    print(id(c))
    print(id(d))
def use_copy2():
    """
    浅copy，只是copy了一层

    """
    a=[1,2]
    b=[3,4]
    c=[a,b]
    d = copy.copy(c)
    print(id(c))
    print(id(d))
    a[0] = 10
    print(f'c---{c}')
    print(f'd---{d}')
    print('-'*50)
    print(id(c[0]),id(c[1]))
    print(id(d[0]),id(d[1]))

def use_deepcopy():
    """
    递归去copy，不管有多少层，都会新做一个空间，把数据拿进来

    """
    a = [1,2]
    b = [3,4]
    c = [a,b]
    d = copy.deepcopy(c)
    print(id(c))
    print(id(d))
    a[0] = 10
    print(f'c---{c}')
    print(f'd---{d}')

class Hero:
    def __init__(self,name,blood):
        self.name = name
        self.blood = blood
        self.equipment = ['鞋子','指环']

def use_copy_own_obj():
    old_hero = Hero('蚂蚁',90)
    new_hero = copy.deepcopy(old_hero)
    new_hero.blood = 80
    new_hero.equipment.append('药水')
    print(old_hero.equipment)


if __name__ == '__main__':
    # use_copy()
    # use_copy2()
    # use_deepcopy()
    use_copy_own_obj()